package com.iss.apartmentmanage.config.security;

import com.alibaba.fastjson.JSON;
import com.iss.apartmentmanage.model.MyResponseData;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
public class SelfAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        MyResponseData responseBody = new MyResponseData();

        responseBody.setStatus("300");
        responseBody.setMsg("EntryPoint,please login");
        responseBody.setErrorCode(0);

        httpServletResponse.getWriter().write(JSON.toJSONString(responseBody));
    }
}
